package com.caipu.controller.client;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caipu.common.Result;
import com.caipu.entity.Category;
import com.caipu.entity.Tag;
import com.caipu.service.CategoryService;
import com.caipu.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/client")
@CrossOrigin
public class ClientCategoryController {
    
    @Autowired
    private CategoryService categoryService;
    
    @Autowired
    private TagService tagService;
    
    @GetMapping("/categories")
    public Result<List<Category>> getCategories() {
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted", 0);
        queryWrapper.orderByDesc("create_time");
        List<Category> list = categoryService.list(queryWrapper);
        return Result.success(list);
    }
    
    @GetMapping("/tags")
    public Result<List<Tag>> getTags() {
        QueryWrapper<Tag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted", 0);
        queryWrapper.orderByDesc("create_time");
        List<Tag> list = tagService.list(queryWrapper);
        return Result.success(list);
    }
}